package com.citms.remote.service.impl;

import com.citms.remote.client.ConfigClient;
import com.citms.remote.config.properties.SysConfProp;
import com.citms.remote.model.RabbitMQConfigModel;
import com.citms.remote.model.ResultInfoModel;
import com.citms.remote.service.ConfigService;
import com.citms.remote.util.BeanTool;
import com.citms.remote.util.CloudUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("configService")
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    private SysConfProp sysConfProp;

    @Autowired
    private ConfigClient configClient;

    @Override
    public Map<String, Object> getConfigByCategoryNo(String categoryNo) {
        ResultInfoModel<Map<String, Object>> infoModel = configClient.getConfigByCategoryNo(categoryNo);
        return CloudUtils.getResult(infoModel);
    }

    @Override
    public RabbitMQConfigModel getRabbitMQConfig() {
        Map<String, Object> config = getConfigByCategoryNo(sysConfProp.getRabbitMQConfigcategoryNo());
        return BeanTool.mapToObject(config,RabbitMQConfigModel.class);
    }
}
